package com.dries.portal.module.convener.service.impl;

import cn.hutool.json.JSONUtil;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.dries.security.validate.code.captcha.sms.SmsCodeSender;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description:
 * @Author ZSY
 * @createTime 2020/10/19 14:40
 */
@Slf4j
@Component("orderPaySmsSender")
public class OrderPaySmsSender implements SmsCodeSender {

    @Override
    public void send(String mobile, String code) {
        log.info("向手机【" + mobile + "】发送短信提示: " + code);
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAIeXAMLldj63MX", "hShC2dsTrRkiU5tdyP8MySY46kNWM9");
        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();
        request.setSysMethod(MethodType.POST);
        request.setSysDomain("dysmsapi.aliyuncs.com");
        request.setSysVersion("2017-05-25");
        request.setSysAction("SendSms");
        request.putQueryParameter("RegionId", "cn-hangzhou");

        request.putQueryParameter("SignName", "又享聚");
        request.putQueryParameter("PhoneNumbers", mobile);
        request.putQueryParameter("TemplateCode", "SMS_204940001");
        Map<String, Object> map = new HashMap<>();
        map.put("order_sn", code);
        request.putQueryParameter("TemplateParam", JSONUtil.toJsonStr(map));
        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }

}
